package com.czxy.controller;

import com.czxy.common.vo.Result;
import com.czxy.pojo.TCustomsPass;
import com.czxy.pojo.TCustomsPassDetail;
import com.czxy.service.CustomsPassDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author likk
 * @create 2018/9/5
 */
@RestController
@RequestMapping("/customsPass/detail")
@Slf4j
public class CustomsPassDetailController {

    @Autowired
    private CustomsPassDetailService customsPassDetailService;

    /**
     * 新增关卡详情
     * @param customsPassDetail
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public Result addUser(@RequestBody TCustomsPassDetail customsPassDetail) {

        try {
            customsPassDetail.setStatus(1);
            customsPassDetailService.save(customsPassDetail);

            // 保存关卡详情

            return Result.build(200, "新增成功！");
        } catch (Exception e) {
            log.error("新增关卡信息失败,错误信息：" + e.getMessage());

            return Result.build(500, "新增失败！");
        }

    }

    /**
     * 更新关卡详情信息
     * @param customsPassDetail
     * @return
     */
    @RequestMapping(value = "update", method = RequestMethod.POST)
    public Result update(@RequestBody TCustomsPassDetail customsPassDetail) {
        try {
            customsPassDetailService.updateSelective(customsPassDetail);

            return Result.build(200, "修改成功！");
        } catch (Exception e) {
            log.error("更新关卡信息失败,错误信息：" + e.getMessage());

            return Result.build(500, "修改失败！");
        }
    }
}
